'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var QueryCard = function (_React$Component) {
    _inherits(QueryCard, _React$Component);

    function QueryCard(props) {
        _classCallCheck(this, QueryCard);

        var _this = _possibleConstructorReturn(this, (QueryCard.__proto__ || Object.getPrototypeOf(QueryCard)).call(this, props));

        _this.pageCount = 0;
        _this.state = { cardList: [] };

        _this.cardTypeMap = {
            's': '超级卡',
            'n': '普通卡'
        };
        return _this;
    }

    _createClass(QueryCard, [{
        key: 'updateCardList',
        value: function updateCardList(page, pageSize) {
            var _this2 = this;

            var commSelect = this.refs.commSelect;
            var roomInfo = commSelect.commCode + commSelect.buildingCode + commSelect.unitCode + commSelect.floorCode + commSelect.roomCode;
            var params = {
                page: page,
                pageSize: pageSize,
                roomInfo: roomInfo,
                ownerName: this.refs.ownerName.value,
                state: this.refs.state.value,
                cardType: this.refs.cardType.value
            };

            postJson("/card/query.x", params, function (data) {
                _this2.pageCount = data.data.size;
                _this2.setState({ cardList: data.data.list });
            });
        }
    }, {
        key: 'onCommChange',
        value: function onCommChange() {
            this.refs.table.refresh();
        }
    }, {
        key: 'view',
        value: function view(obj) {
            var param = {};
            param.cardNo = obj;
            postJson("/card/findCard.x", $.param(param), function (data) {
                data = data.data;
                var output = "<hr/>";
                if (data.cardInfo.cardType == 'n') {
                    for (var i = 0; i < data.cardPerms.length; i++) {
                        output += '&nbsp&nbsp&nbsp&nbsp' + data.cardPerms[i].devStr + '&nbsp&nbsp&nbsp&nbsp<br><hr/>';
                    }
                } else if (data.cardInfo.cardType == 's') {
                    output += '&nbsp&nbsp&nbsp&nbsp[' + data.commName + '] 小区所有权限&nbsp&nbsp&nbsp&nbsp<hr/>';
                }
                layui.layer.open({
                    title: '该卡权限',
                    type: 1,
                    shadeClose: true,
                    content: output
                });
            });
        }
    }, {
        key: 'saveNewExpire',
        value: function saveNewExpire() {
            var _this3 = this;

            var params = this.refs.expireModal.value;
            var newDate = this.refs.newExpire.value;
            if (params.expandDate) {
                var params2 = { cardNo: params.cardNo, endDate: newDate };
                postJson("/card/delayEndDate.x", params2, function () {
                    layui.layer.msg("修改成功");
                    _this3.refs.table.refresh();
                });
            } else {
                params.endDate = newDate;
                console.log(params);
                postJson("/card/lost.x", params, function () {
                    layui.layer.alert("恢复成功！");
                    _this3.refs.table.refresh();
                });
            }
            this.refs.newExpire.value = "";
            this.refs.expireModal.close();
        }
    }, {
        key: 'lost',
        value: function lost(card, state) {
            var _this4 = this;

            var param = {};
            param.cardNo = card.cardNo;
            param.LostOrResume = state;
            var confirmStr = state ? "确定要恢复该卡么" : "确定要挂失该卡么?挂失后改卡将无法使用！";
            var successStr = state ? "恢复成功！" : "挂失成功！";
            layui.layer.confirm(confirmStr, {
                btn: ['确认', '取消'], btn1: function btn1() {
                    if (state == 'expiryResume') {
                        _this4.refs.expireModal.show({ value: param });
                    } else {
                        postJson("/card/lost.x", param, function () {
                            layui.layer.alert(successStr);
                            _this4.refs.table.refresh();
                        });
                    }
                }
            });
        }
    }, {
        key: 'delete',
        value: function _delete(card) {
            var _this5 = this;

            layui.layer.confirm("确认删除此卡的记录信息么?<br>(删除不会影响挂失,但会影响恢复此卡，最好确认卡片已丢失)", function () {
                postJson("/card/delete.x", { cardNo: card.cardNo }, function () {
                    layui.layer.msg("删除成功!");
                    _this5.refs.table.refresh();
                });
            });
        }
    }, {
        key: 'expandDate',
        value: function expandDate(card) {
            var _this6 = this;

            layui.layer.confirm("确认要修改过期时间么?", function () {
                _this6.refs.expireModal.show({ value: { expandDate: true, cardNo: card.cardNo } });
            });
        }
    }, {
        key: 'search',
        value: function search() {
            this.updateCardList(1, 10);
        }
    }, {
        key: 'getCardOps',
        value: function getCardOps(card) {
            var _this7 = this;

            var ret = [];
            var state = card.state;
            ret.push(React.createElement(
                Button,
                { btnType: 'normal', size: 'xs', onClick: function onClick() {
                        return _this7.view(card.cardNo);
                    } },
                '\u67E5\u770B'
            ));
            if (state == '01' || state == '03') {
                ret.push(React.createElement(
                    Button,
                    { btnType: 'warm', size: 'xs', onClick: function onClick() {
                            return _this7.lost(card);
                        } },
                    '\u6302\u5931'
                ));
                ret.push(React.createElement(
                    Button,
                    { btnType: 'primary', size: 'xs', onClick: function onClick() {
                            return _this7.expandDate(card);
                        } },
                    '\u65F6\u6548'
                ));
            } else if (state == '02') {
                ret.push(React.createElement(
                    Button,
                    { btnType: 'disabled', size: 'xs' },
                    '\u6302\u5931'
                ));
                ret.push(React.createElement(
                    Button,
                    { size: 'xs', onClick: function onClick() {
                            return _this7.lost(card, 'resume');
                        } },
                    '\u6062\u590D'
                ));
            } else if (state == 'E') {
                ret.push(React.createElement(
                    Button,
                    { btnType: 'disabled', size: 'xs' },
                    '\u8FC7\u671F'
                ));
                ret.push(React.createElement(
                    Button,
                    { size: 'xs', onClick: function onClick() {
                            return _this7.lost(card, 'expiryResume');
                        } },
                    '\u6062\u590D'
                ));
                ret.push(React.createElement(
                    Button,
                    { btnType: 'danger', size: 'xs', onClick: function onClick() {
                            return _this7.delete(card);
                        } },
                    '\u5220\u9664'
                ));
            }

            return ret;
        }
    }, {
        key: 'render',
        value: function render() {
            var _this8 = this;

            return React.createElement(
                Frame,
                { header: '\u95E8\u7981\u5361\u5217\u8868' },
                React.createElement(
                    Form,
                    { ref: 'form', type: 'pane' },
                    React.createElement(
                        Item,
                        null,
                        React.createElement(
                            Label,
                            null,
                            '\u59D3\u540D'
                        ),
                        React.createElement(Input, { ref: 'ownerName' }),
                        React.createElement(
                            Select,
                            { ref: 'state' },
                            React.createElement(
                                'option',
                                { value: '' },
                                '\u5361\u72B6\u6001'
                            ),
                            React.createElement(
                                'option',
                                { value: '01' },
                                '\u5728\u7528'
                            ),
                            React.createElement(
                                'option',
                                { value: '02' },
                                '\u505C\u7528'
                            ),
                            React.createElement(
                                'option',
                                { value: 'E' },
                                '\u8FC7\u671F'
                            )
                        ),
                        React.createElement(
                            Select,
                            { ref: 'cardType' },
                            React.createElement(
                                'option',
                                { value: '' },
                                '\u5361\u7C7B\u522B'
                            ),
                            React.createElement(
                                'option',
                                { value: 'n' },
                                '\u666E\u901A\u5361'
                            ),
                            React.createElement(
                                'option',
                                { value: 's' },
                                '\u8D85\u7EA7\u5361'
                            )
                        )
                    ),
                    React.createElement(
                        Item,
                        null,
                        React.createElement(
                            Label,
                            null,
                            '\u697C\u680B\u4FE1\u606F'
                        ),
                        React.createElement(LayuiCommSelect, { ref: 'commSelect', onChangeComm: function onChangeComm(comm) {
                                return _this8.onCommChange(comm);
                            } }),
                        React.createElement(
                            Button,
                            { onClick: function onClick() {
                                    return _this8.search();
                                } },
                            '\u67E5\u8BE2'
                        )
                    ),
                    React.createElement(
                        Table,
                        { ref: 'table', count: this.pageCount, pageOnClick: function pageOnClick(page, pageSize) {
                                return _this8.updateCardList(page, pageSize);
                            }, size: 'sm' },
                        React.createElement(
                            'thead',
                            null,
                            React.createElement(
                                'tr',
                                null,
                                React.createElement(
                                    'th',
                                    null,
                                    '\u95E8\u7981\u5361\u7F16\u53F7'
                                ),
                                React.createElement(
                                    'th',
                                    null,
                                    '\u4E1A\u4E3B\u540D\u79F0'
                                ),
                                React.createElement(
                                    'th',
                                    null,
                                    '\u4F4F\u5B85\u4FE1\u606F'
                                ),
                                React.createElement(
                                    'th',
                                    null,
                                    '\u5F00\u5361\u65F6\u95F4'
                                ),
                                React.createElement(
                                    'th',
                                    null,
                                    '\u6709\u6548\u671F\u81F3'
                                ),
                                React.createElement(
                                    'th',
                                    null,
                                    '\u6700\u540E\u4FEE\u6539\u65F6\u95F4'
                                ),
                                React.createElement(
                                    'th',
                                    null,
                                    '\u5361\u7C7B\u578B'
                                ),
                                React.createElement(
                                    'th',
                                    null,
                                    '\u64CD\u4F5C'
                                )
                            )
                        ),
                        React.createElement(
                            'tbody',
                            null,
                            this.state.cardList.length > 0 ? this.state.cardList.map(function (card) {
                                return React.createElement(
                                    'tr',
                                    null,
                                    React.createElement(
                                        'td',
                                        null,
                                        card.cardNo
                                    ),
                                    React.createElement(
                                        'td',
                                        null,
                                        card.ownerName
                                    ),
                                    React.createElement(
                                        'td',
                                        null,
                                        card.roomName
                                    ),
                                    React.createElement(
                                        'td',
                                        null,
                                        card.beginDate
                                    ),
                                    React.createElement(
                                        'td',
                                        null,
                                        card.endDate ? card.endDate.substr(0, 10) : '永久'
                                    ),
                                    React.createElement(
                                        'td',
                                        null,
                                        card.lastModifyTime
                                    ),
                                    React.createElement(
                                        'td',
                                        { style: card.cardType === 's' ? { color: 'green', fontWeight: 700 } : {} },
                                        _this8.cardTypeMap[card.cardType]
                                    ),
                                    React.createElement(
                                        'td',
                                        null,
                                        _this8.getCardOps(card)
                                    )
                                );
                            }) : ''
                        )
                    ),
                    React.createElement(
                        Modal,
                        { title: '\u8BF7\u91CD\u65B0\u8C03\u6574\u8FC7\u671F\u65F6\u95F4', ref: 'expireModal' },
                        React.createElement(DateSelect, { placeHolder: '\u4E0D\u586B\u5219\u8868\u793A\u6C38\u4E45', ref: 'newExpire', min: 1 }),
                        '\xA0',
                        React.createElement(
                            Button,
                            { 'lay-submit': 'true', onClick: function onClick() {
                                    return _this8.saveNewExpire();
                                } },
                            '\u786E\u5B9A'
                        )
                    )
                )
            );
        }
    }]);

    return QueryCard;
}(React.Component);

ReactDOM.render(React.createElement(QueryCard, null), document.getElementById("queryCard"));